//
//  UserGuideViewController.m
//  KJDH
//
//  Created by lanou on 15/12/23.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "UserGuideViewController.h"
#import "RootViewController.h"
#import "LeftSortViewController.h"
#import "LeftSlideViewController.h"
#import "AppDelegate.h"
@interface UserGuideViewController ()<UIScrollViewDelegate>

@property (nonatomic, strong)UIPageControl *pageView;

@property (nonatomic, strong)UIScrollView *scrollView;

@end


@implementation UserGuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor grayColor];
    [self initGuide]; //加载新用户指导页面
    
    [self.view addSubview:self.pageView];
    [self.pageView addTarget:self action:@selector(changePage:) forControlEvents:(UIControlEventValueChanged)];
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.bounces = NO;
    
    // Do any additional setup after loading the view.
}


- (UIPageControl *)pageView {
    if (!_pageView) {
        _pageView = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, kWidth / 2, kWidth / 10)];
        _pageView.center = CGPointMake(kWidth / 2, kHeight - kWidth / 10);
        _pageView.numberOfPages = 4;
    }
    return _pageView;
}
- (void)changePage:(UIPageControl *)pageControl {
    self.scrollView.contentOffset = CGPointMake(kWidth * pageControl.currentPage, 0);
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    NSInteger page = scrollView.contentOffset.x / kWidth;
    self.pageView.currentPage = page;
    
}

//加载新用户指导页面
- (void)initGuide{
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
    [self.scrollView setContentSize:CGSizeMake(kWidth *4, 0)];
    [self.scrollView setPagingEnabled:YES]; //视图整页显示
//    [scrollView setBounces:NO]; //避免弹跳效果，避免把根视图露出来
    self.scrollView.delegate = self;
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
    [imageView setImage:[UIImage imageNamed:@"first2"]];
    [self.scrollView addSubview:imageView];
    
    
    UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(kWidth, 0, kWidth, kHeight)];
    [imageView1 setImage:[UIImage imageNamed:@"first4"]];
    [self.scrollView addSubview:imageView1];
    
    UIImageView *imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(kWidth * 2, 0, kWidth, kHeight)];
    [imageView2 setImage:[UIImage imageNamed:@"first3"]];
    [self.scrollView addSubview:imageView2];
    
    UIImageView *imageView3 = [[UIImageView alloc]initWithFrame:CGRectMake(kWidth * 3, 0, kWidth, kHeight)];
    [imageView3 setImage:[UIImage imageNamed:@"first1"]];
    imageView3.userInteractionEnabled = YES;//打开imageView3的用户交互，否则下面的button无法响应
    [self.scrollView addSubview:imageView3];
    
    
    UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)]; //在imageView3上加载一个透明的button
    [button setTitle:@"点击进入 >>" forState:(UIControlStateNormal)];
    [button setFrame:CGRectMake((kWidth - 200) / 2, kHeight - 80, 200, 30)];
    [button addTarget:self action:@selector(firstpressed) forControlEvents:(UIControlEventTouchUpInside)];
    [imageView3 addSubview:button];
    
    [self.view addSubview:self.scrollView];
    
    
    
}

- (void)firstpressed{
    
    
    //主页面设置
    RootViewController *rootVC = [[RootViewController alloc] init];
    rootVC.title = @"车友管家";
    AppDelegate *tempAppdelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    tempAppdelegate.mainNC = [[UINavigationController alloc] initWithRootViewController:rootVC];
    tempAppdelegate.mainNC.navigationBar.barTintColor = kBarColor;
    [tempAppdelegate.mainNC.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    //左抽屉设置
    LeftSortViewController *leftSoutVC = [[LeftSortViewController alloc]init];
    
    tempAppdelegate.leftSlideVC = [[LeftSlideViewController alloc] initWithLeftView:leftSoutVC andMainView:tempAppdelegate.mainNC];
    
    [self presentViewController:tempAppdelegate.leftSlideVC animated:YES completion:nil];
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
